<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<div>
	<c:if test="${sessionScope.login}">
		<button onclick="location.href='${scriptPath}?action=test.solve&id=${test.id}'">Làm</button>
		<c:if test="${sessionScope.user.group=='admin'}">
			<button onclick="location.href='${scriptPath}?action=test.addquestion&id=${test.id}'">Thêm câu hỏi</button>
			<button onclick="location.href='${scriptPath}?action=test.addsection&id=${test.id}'">Thêm mục</button>
			<button onclick="location.href='${scriptPath}?action=test.list&tl_submit=delete&tl_tests=${test.id}'">Xóa</button>
		</c:if>
	</c:if>
	<button onclick="location.href='${scriptPath}?action=test.list'">Quay về</button>
</div>

<div>
<c:if test="${sessionScope.login}">
	<div style="float:right">
		<a href='${scriptPath}?action=test.editinfo&id=${test.id}'>Sửa thông tin</a>
	</div>
</c:if>
<h3>${test.name}</h3>
<p><b>Mô tả:</b> ${test.description}</p>
<p><b>Thời gian:</b> ${test.time} phút</p>
</div>

<c:set var="type" value="${test.type=='radio' ? 'radio' : 'checkbox'}"></c:set>
<c:set var="i" value="1"></c:set>

<c:forEach items="${test.sections}" var="section">
<div>
	<c:if test="${user.group=='admin'}">
		<div style="float:right">
			<a href="${scriptPath}?action=test.deletesection&sectionId=${section.id}&id=${test.id}">Xóa</a> -
			<a href="${scriptPath}?action=test.sectionup&sectionId=${section.id}&id=${test.id}">Lên trên</a> -
			<a href="${scriptPath}?action=test.sectiondown&sectionId=${section.id}&id=${test.id}">Xuống dưới</a>
		</div>
	</c:if>

	<h3><a href="${scriptPath}?action=test.editsectioninfo&id=${section.id}">
		${(empty section.text) ? "&lt;Mục mặc định&gt;" : section.text}
	</a></h3>

	<c:forEach items="${section.questions}" var="question">
		<div>
			<c:if test="${user.group=='admin'}">
				<div style="float:right">
					<a href="${scriptPath}?action=test.deletequestion&id=${test.id}&questionId=${question.id}">xóa</a>
				</div>
			</c:if>
			
			<p><b><a href="?action=question.view&id=${question.id}">Câu ${i}</a></b>
			</p>
			${question.content}
			<ul style="list-style:none">
			<c:forEach items="${question.answers}" var="answer">
				<li>
					<label><input type="${type}" ${answer.correct ? 'checked' : ''} disabled></input>
					${answer.content}</label>
				</li>
			</c:forEach>
			</ul>
		</div>
		<c:set var="i" value="${i+1}"></c:set>
	</c:forEach>
</div>
</c:forEach>

<div>
	<c:if test="${sessionScope.login}">
		<button onclick="location.href='${scriptPath}?action=test.solve&id=${test.id}'">Làm</button>
		<c:if test="${sessionScope.user.group=='admin'}">
			<button onclick="location.href='${scriptPath}?action=test.addquestion&id=${test.id}'">Thêm câu hỏi</button>
			<button onclick="location.href='${scriptPath}?action=test.addsection&id=${test.id}'">Thêm mục</button>
			<button onclick="location.href='${scriptPath}?action=test.list&tl_submit=delete&tl_tests=${test.id}'">Xóa</button>
		</c:if>
	</c:if>
	<button onclick="location.href='${scriptPath}?action=test.list'">Quay về</button>
</div>
